package eu.tolu.cableSpotter.help;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import eu.tolu.cableSpotter.R;

import android.os.AsyncTask;
import android.widget.TextView;

public class RetreiveFeedTask extends AsyncTask<String, Void, String>{
	
	

	@Override
	protected String doInBackground(String... params) {
		Document doc = null;
		try {
			doc = Jsoup.connect("http://www.rixen-seilbahnen.de/deutsch/referenzen/europa/europa.html").get();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String title = doc.title();
		System.out.println(title);

		Element table = doc.getElementsByClass("referenzen").first();
		
		for(Element tabrow : table.select("tr")){
			System.out.println("---------");
		
			tabrow.select("br").remove();

			for(int i = 0; i<3; i++){
				
				
				if(i==0){
					String location = tabrow.select("td").get(i).text();
					System.out.println("Ort: "+ location);
				}
				else if (i==1) {
					Element tabrow2 = tabrow.clone();
					tabrow2.select("a").remove();
					
					String contact = tabrow2.select("td").get(i).text();
					String website = tabrow.select("td").get(i).select("a").first().attr("href");
					
					System.out.println("Kontakt: "+ contact);
					System.out.println("Website: "+ website);
				}
				else if (i == 2) {
					String image = "";
					if(tabrow.select("td").get(i).children().first() != null)
						image = tabrow.select("td").get(i).children().first().attr("abs:src");
					System.out.println("Bild: "+ image);
					
				}
			}
		}
		return "test";
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
//		super.onPostExecute(result);
//		TextView txt = (TextView) findViewById(R.id.list_text);
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
//		super.onPreExecute();
	}

}
